package com.dlc.garbagerecyclebox.bean;


import com.dlc.commonbiz.base.serialport.utils.ByteUtil;
import com.dlc.garbagerecyclebox.GarbageRecyclerBoxProtocol;

import java.util.ArrayList;

/**
 * @author :      fangbingran
 * @aescription : 回收信息
 * @date :        2019/08/01  20:02
 */
public class RecyclingInfoBean extends DeviceInfoBean {
    /**
     * 执行动作
     */
    private byte executeAction;
    /**
     * 量
     */
    private float amount;

    /**
     * 副柜：开门前称重
     *
     * @return
     */
    public boolean isWeighingBeforeOpenDoor() {
        return executeAction == GarbageRecyclerBoxProtocol.DeliveryCmd.CMD_WEIGHING_BEFORE_OPEN_DOOR;
    }
    public RecyclingInfoBean(DeviceInfoBean deviceInfoBean) {
        super(deviceInfoBean);
    }
    /**
     * 开下舱门电磁锁
     *
     * @return
     */
    public boolean isOpenELock() {
        return executeAction == GarbageRecyclerBoxProtocol.DeliveryCmd.CMD_OPEN_HATCH_DOOR;
    }

    /**
     * 等待电磁锁关闭
     *
     * @return
     */
    public boolean isWaitingELockClose() {
        return executeAction == GarbageRecyclerBoxProtocol.DeliveryCmd.CMD_FIRST_PHOTOELECTRIC_TRIGGER;
    }

    /**
     * 副柜：关门后称重
     *
     * @return
     */
    public boolean isWeighingAfterCloseDoor() {
        return executeAction == GarbageRecyclerBoxProtocol.DeliveryCmd.CMD_WEIGHING_AFTER_CLOSE_DOOR;
    }

    /**
     * 投递完成
     *
     * @return
     */
    public boolean isDeliveryCompleted() {
        return executeAction == GarbageRecyclerBoxProtocol.DeliveryCmd.CMD_DELIVERY_COMPLETED;
    }

    @Override
    public String toString() {
        return "回收流程 ,状态命令::" + ByteUtil.bytes2HexStr(new byte[]{executeAction}) + ",说明:" + geExplain() + ",结果:" + getDeviceNumberExplain() + "," + super.toString();
    }

    public String getDeviceNumberExplain() {
        if (isMainCabinet()) {
            return "本次回收饮料瓶数量（默认为累计饮料瓶数量）:" + amount;
        }
        return "本次回收重量（由回收前后重量差计算所得）:" + amount;
    }


    private String geExplain() {
        if (isWeighingBeforeOpenDoor()) {
            return "副柜：开门前称重";
        }
        if (isOpenELock()) {
            return " 开下舱门电磁锁";
        }
        if (isWaitingELockClose()) {
            return " 等待电磁锁关闭";
        }
        if (isWeighingAfterCloseDoor()) {
            return " 副柜：关门后称重";
        }
        if (isDeliveryCompleted()) {
            return " 投递完成";
        }
        return "未知状态:";
    }



    public String getStrDeliveryCmd() {
        return ByteUtil.bytes2HexStr(new byte[]{
                executeAction});
    }

    public byte getExecuteAction() {
        return executeAction;
    }

    public void setExecuteAction(byte executeAction) {
        this.executeAction = executeAction;
    }

    public float getAmount() {
        return amount;
    }

    public void setAmount(float amount) {
        this.amount = amount;
    }
    @Override
    public RecyclingInfoBean clone() {
        return (RecyclingInfoBean) super.clone();
    }
}
